# @Time    : 2020/6/19 17:34
# @Author  : T-
# @Site    : 
# @File    : 83-Remove Duplicates from Sorted List.py
# @Software: PyCharm


# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        # method-1:递归法
        if head is None or head.next is None:
            return head
        head.next = self.deleteDuplicates(head.next)
        head.next = head.next.next if head.val == head.next.val else head.next
        return head

        """
        # method-2:直接法
        curr = head
        while curr is not None and curr.next is not None:
            if curr.next.val == curr.val:
                curr.next = curr.next.next
            else:
                curr = curr.next
        return  head
        """

